package com.bosssoft.springboot.demo1.controller;



import com.bosssoft.springboot.demo1.model.User;
import com.bosssoft.springboot.demo1.service.UserService;
import com.bosssoft.springboot.demo1.util.ResponseUtil;
import com.bosssoft.springboot.demo1.util.result.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


/**
 * @description 用户逻辑控制层
 * @author ChenTong
 * @date 2020-6-10
 */
@Slf4j
@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserService userService;

    /**
     * @description 查询用户列表
     * @return 封装好的json格式
     */
    @GetMapping("/list")
    @ResponseBody
    public Response<User> listAllUser(){
        return ResponseUtil.success(userService.listAll());
    }

    /**
     * @description 添加用户
     * @return 封装好的json格式
     */
    @PostMapping("/add")
    @ResponseBody
    public Response<Boolean> add(@RequestBody User user){
        return ResponseUtil.success(userService.insert(user));
    }

    /**
     * @description 通过id删除用户
     * @return 封装好的json格式
     */
    @GetMapping("/remove")
    @ResponseBody
    public Response<Boolean> remove(@RequestParam("id") Long id){
        return ResponseUtil.success(userService.remove(id));
    }

    /**
     * @description 更新用户
     * @return 封装好的json格式
     */
    @PostMapping("/update")
    @ResponseBody
    public Response<Boolean> update(@RequestBody User user){
        return ResponseUtil.success(userService.update(user));
    }


}
